﻿using Newtonsoft.Json;
using ReferenceTemplate.Models;
using ReferenceTemplate.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;

namespace ReferenceTemplate.Windows8.Services
{
    public class DataService : IDataService
    {
        private static string dataFile = "ms-appx:///Content/config.json";
        public async Task<AppData> LoadData()
        {
            AppData data = null;

            StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(dataFile));

            if (file != null)
            {
                string json = await FileIO.ReadTextAsync(file);

                data = JsonConvert.DeserializeObject<AppData>(json);
            }

            return data;
        }
    }
}